/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package view;

import control.CheckController;
import control.OtoController;
import java.sql.Date;
import java.sql.SQLException;
import java.util.Calendar;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import model.DaiHan;
import model.NganHan;

/**
 *
 * @author Dom
 */
public class frmCheckInOut extends javax.swing.JFrame {

    /**
     * Creates new form CheckInOut
     */
    public frmCheckInOut() {
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        txtNhapbiensoxe = new javax.swing.JTextField();
        btnTim = new javax.swing.JButton();
        jScrollPane2 = new javax.swing.JScrollPane();
        tbCheck = new javax.swing.JTable();
        jLabel2 = new javax.swing.JLabel();
        jsngayvao = new javax.swing.JSpinner();
        jsthangvao = new javax.swing.JSpinner();
        jsnamvao = new javax.swing.JSpinner();
        jLabel3 = new javax.swing.JLabel();
        rbThang = new javax.swing.JRadioButton();
        rbQuy = new javax.swing.JRadioButton();
        jLabel4 = new javax.swing.JLabel();
        jdNgaythanhtoan = new javax.swing.JSpinner();
        jsThangthanhtoan = new javax.swing.JSpinner();
        jsNamthanhtoan = new javax.swing.JSpinner();
        jLabel5 = new javax.swing.JLabel();
        jsNgayHanthantoan = new javax.swing.JSpinner();
        jsthangHanthanhtoan = new javax.swing.JSpinner();
        jsNamHanthanhtoan = new javax.swing.JSpinner();
        jLabel6 = new javax.swing.JLabel();
        txtDongia = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        txtThanhtien = new javax.swing.JTextField();
        btnThanhtoan = new javax.swing.JButton();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        txtTongsogio = new javax.swing.JTextField();
        jLabel13 = new javax.swing.JLabel();
        txtDonGiaNH = new javax.swing.JTextField();
        jLabel14 = new javax.swing.JLabel();
        txtThanhTienNH = new javax.swing.JTextField();
        btnCheckIN = new javax.swing.JButton();
        btnCheckOUT = new javax.swing.JButton();
        jLabel15 = new javax.swing.JLabel();
        jLabel16 = new javax.swing.JLabel();
        jLabel17 = new javax.swing.JLabel();
        jLabel18 = new javax.swing.JLabel();
        txtNgayGioVao = new javax.swing.JTextField();
        txtNgayGioRa = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        jLabel1.setText("Nhập biển số xe");

        btnTim.setText("Tìm");
        btnTim.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnTimActionPerformed(evt);
            }
        });

        tbCheck.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tbDanhSach_Click(evt);
            }
        });
        jScrollPane2.setViewportView(tbCheck);

        jLabel2.setText("Ngày giờ vào  ");

        jsngayvao.setEnabled(false);

        jsthangvao.setEnabled(false);

        jsnamvao.setEnabled(false);

        jLabel3.setText("Thanh toán theo");

        rbThang.setText("Tháng");
        rbThang.setEnabled(false);
        rbThang.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                Thang_Click(evt);
            }
        });

        rbQuy.setText("Quý");
        rbQuy.setEnabled(false);
        rbQuy.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                Quy_Click(evt);
            }
        });

        jLabel4.setText("Ngày thanh toán");

        jdNgaythanhtoan.setEnabled(false);

        jsThangthanhtoan.setEnabled(false);

        jsNamthanhtoan.setEnabled(false);

        jLabel5.setText("Hạn thanh toán tiếp theo");

        jsNgayHanthantoan.setEnabled(false);

        jsthangHanthanhtoan.setEnabled(false);

        jsNamHanthanhtoan.setEnabled(false);

        jLabel6.setText("Đơn giá mỗi tháng");

        txtDongia.setEditable(false);
        txtDongia.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        txtDongia.setText("800");
        txtDongia.setEnabled(false);

        jLabel7.setText("Tổng thành tiền");

        txtThanhtien.setEditable(false);
        txtThanhtien.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        txtThanhtien.setEnabled(false);

        btnThanhtoan.setText("Thanh toán");
        btnThanhtoan.setEnabled(false);
        btnThanhtoan.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnThanhtoanActionPerformed(evt);
            }
        });

        jLabel8.setText(".000 VND");

        jLabel9.setText(".000 VND");

        jLabel10.setText("Ngày giờ vào");

        jLabel11.setText("Ngày giờ ra");

        jLabel12.setText("Tổng số giờ");

        txtTongsogio.setEditable(false);
        txtTongsogio.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        txtTongsogio.setEnabled(false);

        jLabel13.setText("Đơn giá mỗi giờ");

        txtDonGiaNH.setEditable(false);
        txtDonGiaNH.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        txtDonGiaNH.setText("20");
        txtDonGiaNH.setEnabled(false);

        jLabel14.setText("Tổng thành tiền");

        txtThanhTienNH.setEditable(false);
        txtThanhTienNH.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        txtThanhTienNH.setEnabled(false);

        btnCheckIN.setText("Check IN");
        btnCheckIN.setEnabled(false);
        btnCheckIN.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCheckINActionPerformed(evt);
            }
        });

        btnCheckOUT.setText("Check OUT");
        btnCheckOUT.setEnabled(false);
        btnCheckOUT.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCheckOUTActionPerformed(evt);
            }
        });

        jLabel15.setText(".000 VND");

        jLabel16.setText(".000 VND");

        jLabel17.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel17.setText("Gửi dài hạn");

        jLabel18.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel18.setText("Gửi ngắn hạn");

        txtNgayGioVao.setEditable(false);
        txtNgayGioVao.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        txtNgayGioVao.setEnabled(false);

        txtNgayGioRa.setEditable(false);
        txtNgayGioRa.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
        txtNgayGioRa.setEnabled(false);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane2)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addGap(18, 18, 18)
                        .addComponent(txtNhapbiensoxe, javax.swing.GroupLayout.PREFERRED_SIZE, 333, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(btnTim, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(btnThanhtoan, javax.swing.GroupLayout.PREFERRED_SIZE, 294, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addGroup(layout.createSequentialGroup()
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(jLabel5)
                                            .addComponent(jLabel4)
                                            .addComponent(jLabel3)
                                            .addComponent(jLabel2)
                                            .addComponent(jLabel6)
                                            .addComponent(jLabel7))
                                        .addGap(18, 18, 18)
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                            .addGroup(layout.createSequentialGroup()
                                                .addComponent(jdNgaythanhtoan, javax.swing.GroupLayout.PREFERRED_SIZE, 69, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                .addComponent(jsThangthanhtoan)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                .addComponent(jsNamthanhtoan, javax.swing.GroupLayout.PREFERRED_SIZE, 68, javax.swing.GroupLayout.PREFERRED_SIZE))
                                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                                        .addComponent(jsNgayHanthantoan)
                                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                        .addComponent(jsthangHanthanhtoan, javax.swing.GroupLayout.PREFERRED_SIZE, 66, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                        .addComponent(jsNamHanthanhtoan))
                                                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                                        .addComponent(rbThang)
                                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                                        .addComponent(rbQuy))
                                                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                                            .addComponent(txtDongia, javax.swing.GroupLayout.DEFAULT_SIZE, 95, Short.MAX_VALUE)
                                                            .addComponent(txtThanhtien))
                                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                            .addComponent(jLabel8)
                                                            .addComponent(jLabel9)))
                                                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                                        .addComponent(jsngayvao, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                        .addComponent(jsthangvao, javax.swing.GroupLayout.PREFERRED_SIZE, 65, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                        .addComponent(jsnamvao, javax.swing.GroupLayout.PREFERRED_SIZE, 68, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                                .addGap(0, 1, Short.MAX_VALUE)))))
                                .addGap(91, 91, 91))
                            .addGroup(layout.createSequentialGroup()
                                .addGap(81, 81, 81)
                                .addComponent(jLabel17)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(btnCheckIN, javax.swing.GroupLayout.PREFERRED_SIZE, 122, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(btnCheckOUT, javax.swing.GroupLayout.DEFAULT_SIZE, 130, Short.MAX_VALUE))
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(layout.createSequentialGroup()
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(jLabel13)
                                            .addComponent(jLabel14))
                                        .addGap(1, 1, 1)
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                            .addComponent(txtDonGiaNH, javax.swing.GroupLayout.DEFAULT_SIZE, 127, Short.MAX_VALUE)
                                            .addComponent(txtThanhTienNH))
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(jLabel15)
                                            .addComponent(jLabel16)))
                                    .addGroup(layout.createSequentialGroup()
                                        .addGap(43, 43, 43)
                                        .addComponent(jLabel18))
                                    .addGroup(layout.createSequentialGroup()
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(jLabel12)
                                            .addComponent(jLabel10)
                                            .addComponent(jLabel11))
                                        .addGap(14, 14, 14)
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                            .addComponent(txtTongsogio)
                                            .addComponent(txtNgayGioVao)
                                            .addComponent(txtNgayGioRa, javax.swing.GroupLayout.DEFAULT_SIZE, 172, Short.MAX_VALUE))))
                                .addGap(0, 17, Short.MAX_VALUE)))))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(txtNhapbiensoxe, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnTim))
                .addGap(18, 18, 18)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 104, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 35, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel17)
                    .addComponent(jLabel18))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(jsngayvao, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jsthangvao, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jsnamvao, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel10)
                    .addComponent(txtNgayGioVao, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel3)
                        .addComponent(rbQuy)
                        .addComponent(rbThang))
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel11)
                        .addComponent(txtNgayGioRa, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel4)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jdNgaythanhtoan, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jsThangthanhtoan, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jsNamthanhtoan, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel12)
                        .addComponent(txtTongsogio, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(jsNgayHanthantoan, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jsthangHanthanhtoan, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jsNamHanthanhtoan, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel13)
                    .addComponent(txtDonGiaNH, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel15))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6)
                    .addComponent(txtDongia, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel8)
                    .addComponent(jLabel14)
                    .addComponent(txtThanhTienNH, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel16))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel7)
                    .addComponent(txtThanhtien, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel9))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnThanhtoan)
                    .addComponent(btnCheckIN)
                    .addComponent(btnCheckOUT))
                .addGap(57, 57, 57))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    
    //Nút tìm
    private void btnTimActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnTimActionPerformed
        try {
            // TODO add your handling code here:
            
            CheckController.Search(tbCheck, txtNhapbiensoxe.getText());
        } catch (SQLException ex) {
            Logger.getLogger(frmCheckInOut.class.getName()).log(Level.SEVERE, null, ex);
        }
        
    }//GEN-LAST:event_btnTimActionPerformed

    
    //Phương thức ẩn hiện component theo loại gửi
    private void SetVisible(int loaigui)
    {
        if (loaigui==1) //Dài hạn, bật các component dài hạn, tắt component ngắn hạn
        {
            jsngayvao.setEnabled(true);
            jsthangvao.setEnabled(true);
            jsnamvao.setEnabled(true);
            
            rbThang.setEnabled(true);
            rbQuy.setEnabled(true);
            
            jdNgaythanhtoan.setEnabled(true);
            jsThangthanhtoan.setEnabled(true);
            jsNamthanhtoan.setEnabled(true);
            
            jsNgayHanthantoan.setEnabled(true);
            jsthangHanthanhtoan.setEnabled(true);
            jsNamHanthanhtoan.setEnabled(true);
            //=======
            txtNgayGioVao.setEnabled(false);
            txtNgayGioRa.setEnabled(false);
            
            txtTongsogio.setEnabled(false);
            txtDonGiaNH.setEnabled(false);
            txtThanhTienNH.setEnabled(false);
            
            btnCheckIN.setEnabled(false);
            btnCheckOUT.setEnabled(false);
        }
        else        //Ngắn hạn
        {
            jsngayvao.setEnabled(false);
            jsthangvao.setEnabled(false);
            jsnamvao.setEnabled(false);
            
            rbThang.setEnabled(false);
            rbQuy.setEnabled(false);
            
            jdNgaythanhtoan.setEnabled(false);
            jsThangthanhtoan.setEnabled(false);
            jsNamthanhtoan.setEnabled(false);
            
            jsNgayHanthantoan.setEnabled(false);
            jsthangHanthanhtoan.setEnabled(false);
            jsNamHanthanhtoan.setEnabled(false);
            
            txtDongia.setEnabled(false);
            txtThanhtien.setEnabled(false);
            btnThanhtoan.setEnabled(false);
            //======
            
        }
    }
    
    private void SetDH()    //Hàm thiết lập, lấy các thông số của ô tô
    {
        String ngay = tbCheck.getModel().getValueAt(tbCheck.getSelectedRow(), 4).toString();
        String ng[] = ngay.split("-");
        String ng2[] = ng[2].split(" ");
        
        jsngayvao.setValue(Integer.parseInt(ng2[0]));
        jsthangvao.setValue(Integer.parseInt(ng[1]));
        jsnamvao.setValue(Integer.parseInt(ng[0]));
        
        Calendar calendar = Calendar.getInstance();
        jdNgaythanhtoan.setValue(calendar.get(Calendar.DAY_OF_MONTH));
        jsThangthanhtoan.setValue(calendar.get(Calendar.MONTH));
        jsNamthanhtoan.setValue(calendar.get(Calendar.YEAR));
    }
    
    
    private void setNH()    //Hàm thiết lập các component, lấy các thông số của ô tô ngắn hạn
    {
        Object trangthai=tbCheck.getModel().getValueAt(tbCheck.getSelectedRow(), 6);
        Calendar calendar = Calendar.getInstance();
        String ngayvao=""+calendar.get(Calendar.YEAR)+"-"+(calendar.get(Calendar.MONTH)+1)+"-"+calendar.get(Calendar.DAY_OF_MONTH)+" ";
        ngayvao+=calendar.get(Calendar.HOUR_OF_DAY)+":"+calendar.get(Calendar.MINUTE)+":"+calendar.get(Calendar.SECOND);
        
        if (trangthai==null)  //Ở ngoài gara, bật thông tin check in
        {
            txtNgayGioVao.setText(ngayvao);
            txtNgayGioVao.setEnabled(true);
            
            txtNgayGioRa.setEnabled(false);
            txtTongsogio.setEnabled(false);
            
            txtDonGiaNH.setEnabled(false);
            txtThanhTienNH.setEnabled(false);
            
            btnCheckIN.setEnabled(true);
            btnCheckOUT.setEnabled(false);
        }
        else        //Ở trong gara, bật thông tin check out
        {
            txtNgayGioVao.setEnabled(true);
            txtNgayGioVao.setText(tbCheck.getModel().getValueAt(tbCheck.getSelectedRow(), 4).toString().split("\\.")[0]);
            txtNgayGioRa.setText(ngayvao);
            txtNgayGioRa.setEnabled(true);
            
            btnCheckIN.setEnabled(false);
            btnCheckOUT.setEnabled(true);
            
            txtTongsogio.setText(String.valueOf(TinhGio(txtNgayGioVao.getText(),txtNgayGioRa.getText())));
            txtTongsogio.setEnabled(true);
            
            txtDonGiaNH.setEnabled(true);
            
            txtThanhTienNH.setEnabled(true);
            txtThanhTienNH.setText(String.valueOf(Integer.parseInt(txtDonGiaNH.getText())*Integer.parseInt(txtTongsogio.getText())));
        }
    }
    
    //Phương thức tính giờ gửi
    private int TinhGio(String vao, String ra)
    {
        int ngay, gio, phut, giay;
        String ngayvao, giovao, ngayra, giora;
        ngayvao=vao.split(" ")[0];
        giovao=vao.split(" ")[1];
        
        ngayra=ra.split(" ")[0];
        giora=ra.split(" ")[1];
        
        ngay=Integer.parseInt(ngayra.split("-")[2])-Integer.parseInt(ngayvao.split("-")[2]);
        gio=Integer.parseInt(giora.split(":")[0])-Integer.parseInt(giovao.split(":")[0]);
        phut=Integer.parseInt(giora.split(":")[1])-Integer.parseInt(giovao.split(":")[1]);
        giay=Integer.parseInt(giora.split(":")[2])-Integer.parseInt(giovao.split(":")[2]);
        
        if (giay>=1)
            phut+=1;
        if (phut>=1)
            gio+=1;
        gio+=ngay*24;
        return gio;
    }
    
    //Click vào danh sách đẩy thông tin xuống dưới
    private void tbDanhSach_Click(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tbDanhSach_Click
        // TODO add your handling code here:
        int loaigui=Integer.parseInt(tbCheck.getModel().getValueAt(tbCheck.getSelectedRow(), 5).toString());
        
        SetVisible(loaigui);    //Ẩn hiện component tùy loại gửi
        
        if (loaigui==1)
            SetDH();
        else
            setNH();
    }//GEN-LAST:event_tbDanhSach_Click

    
    //Nút thanh toán theo quý được chọn
    private void Quy_Click(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_Quy_Click
        // TODO add your handling code here:
        rbThang.setSelected(false);
        Calendar calendar = Calendar.getInstance();
        jsNgayHanthantoan.setValue(calendar.get(Calendar.DAY_OF_MONTH));
        jsthangHanthanhtoan.setValue(calendar.get(Calendar.MONTH)+3);
        jsNamHanthanhtoan.setValue(calendar.get(Calendar.YEAR));
        
        txtThanhtien.setText(String.valueOf(Integer.parseInt(txtDongia.getText())*3));
        txtThanhtien.setEnabled(true);
        txtDongia.setEnabled(true);
        btnThanhtoan.setEnabled(true);
    }//GEN-LAST:event_Quy_Click

    //Nút thanh toán theo tháng được chọn
    private void Thang_Click(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_Thang_Click
        // TODO add your handling code here:
        rbQuy.setSelected(false);
        Calendar calendar = Calendar.getInstance();
        jsNgayHanthantoan.setValue(calendar.get(Calendar.DAY_OF_MONTH));
        jsthangHanthanhtoan.setValue(calendar.get(Calendar.MONTH)+1);
        jsNamHanthanhtoan.setValue(calendar.get(Calendar.YEAR));
        
        txtThanhtien.setText(String.valueOf(Integer.parseInt(txtDongia.getText())));
        txtThanhtien.setEnabled(true);
        txtDongia.setEnabled(true);
        btnThanhtoan.setEnabled(true);
    }//GEN-LAST:event_Thang_Click

    //Nút thanh toán dài hạn
    private void btnThanhtoanActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnThanhtoanActionPerformed
        // TODO add your handling code here:
        DaiHan dh = new DaiHan();
        
        Calendar cal = Calendar.getInstance();
        cal.set(Integer.parseInt(jsNamHanthanhtoan.getModel().getValue().toString()), Integer.parseInt(jsthangHanthanhtoan.getModel().getValue().toString()), Integer.parseInt(jsNgayHanthantoan.getModel().getValue().toString()));
        dh.setHanThanhToan(new java.sql.Date(cal.getTimeInMillis()));
        
        cal.set(Integer.parseInt(jsNamthanhtoan.getModel().getValue().toString()), Integer.parseInt(jsThangthanhtoan.getModel().getValue().toString()), Integer.parseInt(jdNgaythanhtoan.getModel().getValue().toString()));
        dh.setNgayThanhToan(new java.sql.Date(cal.getTimeInMillis()));
        
        dh.setBienSo(tbCheck.getModel().getValueAt(tbCheck.getSelectedRow(), 0).toString());
        
        dh.setTongTien(Integer.parseInt(txtThanhtien.getText()));
        
        JOptionPane.showMessageDialog(this, OtoController.ThanhToan(tbCheck,dh)+" đã thanh toán");
    }//GEN-LAST:event_btnThanhtoanActionPerformed

    //Nút Check in
    private void btnCheckINActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCheckINActionPerformed
        // TODO add your handling code here:        
        NganHan nh=new NganHan();
        
        Calendar cal = Calendar.getInstance();
        nh.setGioVao(new java.sql.Timestamp(cal.getTimeInMillis()));
        nh.setBienSo(tbCheck.getModel().getValueAt(tbCheck.getSelectedRow(), 0).toString());
        
        JOptionPane.showMessageDialog(this, OtoController.CheckIn(tbCheck,nh)+" đã vào");
    }//GEN-LAST:event_btnCheckINActionPerformed

    //Nút check out
    private void btnCheckOUTActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCheckOUTActionPerformed
        // TODO add your handling code here:
        NganHan nh=new NganHan();
        
        Calendar cal = Calendar.getInstance();
        nh.setGioRa(new java.sql.Timestamp(cal.getTimeInMillis()));
        nh.setBienSo(tbCheck.getModel().getValueAt(tbCheck.getSelectedRow(), 0).toString());
        nh.setTongTien(Integer.parseInt(txtThanhTienNH.getText()));
        
        JOptionPane.showMessageDialog(this, OtoController.CheckOUT(tbCheck,nh)+" đã ra");
    }//GEN-LAST:event_btnCheckOUTActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /*
         * Set the Nimbus look and feel
         */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /*
         * If Nimbus (introduced in Java SE 6) is not available, stay with the
         * default look and feel. For details see
         * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(frmCheckInOut.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(frmCheckInOut.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(frmCheckInOut.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(frmCheckInOut.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /*
         * Create and display the form
         */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new frmCheckInOut().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnCheckIN;
    private javax.swing.JButton btnCheckOUT;
    private javax.swing.JButton btnThanhtoan;
    private javax.swing.JButton btnTim;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JSpinner jdNgaythanhtoan;
    private javax.swing.JSpinner jsNamHanthanhtoan;
    private javax.swing.JSpinner jsNamthanhtoan;
    private javax.swing.JSpinner jsNgayHanthantoan;
    private javax.swing.JSpinner jsThangthanhtoan;
    private javax.swing.JSpinner jsnamvao;
    private javax.swing.JSpinner jsngayvao;
    private javax.swing.JSpinner jsthangHanthanhtoan;
    private javax.swing.JSpinner jsthangvao;
    private javax.swing.JRadioButton rbQuy;
    private javax.swing.JRadioButton rbThang;
    private javax.swing.JTable tbCheck;
    private javax.swing.JTextField txtDonGiaNH;
    private javax.swing.JTextField txtDongia;
    private javax.swing.JTextField txtNgayGioRa;
    private javax.swing.JTextField txtNgayGioVao;
    private javax.swing.JTextField txtNhapbiensoxe;
    private javax.swing.JTextField txtThanhTienNH;
    private javax.swing.JTextField txtThanhtien;
    private javax.swing.JTextField txtTongsogio;
    // End of variables declaration//GEN-END:variables
}
